package JasPerl::Util::Attributes;

use strict;
use warnings;

use JasPerl::Util::Enumeration;
use JasPerl::Util::Exceptions;

sub new {
    my ($class, %attributes) = @_;
    bless \%attributes, $class;
}

sub get_attribute_names {
    return JasPerl::Util::Enumeration->from_list(keys %{$_[0]});
}

sub get_attribute {
    JasPerl::Util::NullPointerException->throw()
        unless defined $_[1];
    return $_[0]->{$_[1]};
}

sub set_attribute {
    JasPerl::Util::NullPointerException->throw()
        unless defined $_[1];
    if (defined $_[2]) {
        $_[0]->{$_[1]} = $_[2];
    } else {
        delete $_[0]->{$_[1]};
    }
}

sub remove_attribute {
    JasPerl::Util::NullPointerException->throw()
        unless defined $_[1];
    delete $_[0]->{$_[1]};
}

1;
